<?php
class FindAttachExpenseAction extends CAction{
	public function run() {
		$code=$_POST['code'];
		if (!preg_match_all('/^MEXP(\d{8})$/', $code, $matches)) {
			echo '代码格式不正确，请正确扫描';
			return;
		}
		$id=intval($matches[1][0]);
		$expense=MaterialExpense::model()->findByPk($id);
		if($expense===null){
			echo '报销单不存在不正确，请正确扫描';
			return;
		}
		if($expense->accountTokenId){
			$accountToken=$expense->accountToken;
			echo '报销单存在，但已附于'.CHtml::link($accountToken->tokenYear.'-'.$accountToken->tokenMonth.' #'.$accountToken->number,
				array('view','id'=>$expense->accountTokenId),array(
					'target'=>'_blank'
				));
			return;
		}
		$this->controller->renderPartial('_attachMaterialExpensePreview',array(
			'model'=>$expense,
			'accountTokenId'=>$_POST['accountTokenId']
			));
	}
}